/*
 * Copyright (C) 2015 MediaTek Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

/******************************************************************************
 * pmic_wrapper.c - Linux pmic_wrapper Driver
 *
 *
 * DESCRIPTION:
 *     This file provid the other drivers PMIC wrapper relative functions
 *
 ******************************************************************************/

#include "mt_pmic_wrap.h"

#include <rtl/string.h>
#include <rtl/print.h>

#define PMIC_WRAP_DEVICE "pmic_wrap"
#define VERSION     "Revision"

static struct mt_pmic_wrap_driver mt_wrp = {NULL};

struct mt_pmic_wrap_driver *get_mt_pmic_wrap_drv(void)
{
	return &mt_wrp;
}
/*this function only used for ROME plus*/
int check_pmic_wrap_init(void)
{
	if (mt_wrp.wacs2_hal == NULL)
		return -1;
	else
		return 0;
}

/* ****************************************************************************** */
/* --external API for pmic_wrap user------------------------------------------------- */
/* ****************************************************************************** */
INT32 pwrap_wacs2(UINT32 write, UINT32 adr, UINT32 wdata, UINT32 *rdata)
{
	if (mt_wrp.wacs2_hal != NULL)
		return mt_wrp.wacs2_hal(write, adr, wdata, rdata);

	RtlPrintf("[WRAP]" "driver need registered!!");
	return -5;

}
INT32 pwrap_read(UINT32 adr, UINT32 *rdata)
{
	return pwrap_wacs2(PWRAP_READ, adr, 0, rdata);
}

INT32 pwrap_write(UINT32 adr, UINT32 wdata)
{
#if defined PWRAP_TRACE
	tracepwrap(adr, wdata);
#endif
	return pwrap_wacs2(PWRAP_WRITE, adr, wdata, 0);
}

/********************************************************************/
/********************************************************************/
/* return value : EINT_STA: [0]: CPU IRQ status in PMIC1 */
/* [1]: MD32 IRQ status in PMIC1 */
/* [2]: CPU IRQ status in PMIC2 */
/* [3]: RESERVED */
/********************************************************************/
UINT32 pmic_wrap_eint_status(void)
{
	return mt_pmic_wrap_eint_status();
}

/********************************************************************/
/* set value(W1C) : EINT_CLR:       [0]: CPU IRQ status in PMIC1 */
/* [1]: MD32 IRQ status in PMIC1 */
/* [2]: CPU IRQ status in PMIC2 */
/* [3]: RESERVED */
/* para: offset is shift of clear bit which needs to clear */
/********************************************************************/
void pmic_wrap_eint_clr(int offset)
{
	mt_pmic_wrap_eint_clr(offset);
}

unsigned int gPWRAPHCK;
unsigned int gPWRAPDBGADDR;